
public class SimpleControl extends Node{
	private static int finalState;
	private static int initialState;
	
	
	private int state;
	private String input;
	private String result;
	
	
	
	/**
	 * this constructor is used to create the root node
	 * @param intialState
	 * @param finalState
	 */
	public SimpleControl(int intialState,int finalState)
	{
		SimpleControl.initialState = state = intialState;
		input = "";
		SimpleControl.finalState = finalState;
	}
	
	
	/**
	 * this constructor is used for extending branches
	 * @param state
	 * @param input
	 */
	private SimpleControl(int state , String input)
	{
		this.state = state;
		this.input  = input;
	}
	@Override
	public Node ApplyZero()
	{
		return new SimpleControl(nextState[state][0] , input+0);
	}

	@Override
	public Node ApplyOne()
	{
		return new SimpleControl(nextState[state][1] , input+1);
	}

	@Override
	public boolean isTerminated()
	{
		boolean  t = state == finalState;
		if(t)
			result = input;
		return t;
	}
	
	@Override
	public boolean isEqual(Node e)
	{
		SimpleControl t = (SimpleControl) e;
		return state == t.state;
	}


	@Override
	public String getResult()
	{
		return result;
	}
	

	
	@Override
	public String toString()
	{
		// TODO Auto-generated method stub
		return state+" "+input;
	}


	@Override
	public String[][] getTable() {
		return new String[][]{{initialState+"", finalState+""}};
	}


}
